package com.kede.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kede.dto.AjaxMessage;
import com.kede.entity.Menu;
import com.kede.entity.Promote;
import com.kede.service.MenuService;
import com.kede.service.PromoteService;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *广告controller
 * @author 【请填写作者】
 * @since 2020-03-30
 */
@Controller
@RequestMapping("/ads")
public class PromoteController {

    @Autowired
    MenuService menuService;
    @Autowired
    PromoteService promoteService;

    /**
     * 首页广告
     * @param id
     * @param model
     * @return
     */
    @GetMapping("/**")
    public String index(
            String id,
            Model model
    ){
        long mid = Long.parseLong(id);
        Promote promote=promoteService.getByMid(mid);
        model.addAttribute("promote",promote);
        return "ads/index";
    }

  /*  *//**
     * 频道广告
     * @param id
     * @param model
     * @return
     *//*
    @GetMapping("channel")
    public String channel(
            String id,
            Model model
    ){
        long mid = Long.parseLong(id);
        Promote promote=promoteService.getByMid(mid);
        model.addAttribute("promote",promote);
        return "ads/channel";
    }

    *//**
     * 列表广告
     * @param id
     * @param model
     * @return
     *//*
    @GetMapping("lists")
    public String list(
            String id,
            Model model
    ){
        long mid = Long.parseLong(id);
        Promote promote=promoteService.getByMid(mid);
        model.addAttribute("promote",promote);
        return "ads/lists";
    }

    *//**
     * 详情广告
     * @param id
     * @param model
     * @return
     *//*
    @GetMapping("details")
    public String details(
            String id,
            Model model
    ){
        long mid = Long.parseLong(id);
        Promote promote=promoteService.getByMid(mid);
        model.addAttribute("promote",promote);
        return "ads/details";
    }*/

    @ResponseBody
    @PostMapping("update")
    public AjaxMessage updeteasd(
            Promote promote
    ){
        AjaxMessage message = new AjaxMessage();
        if (promoteService.updatebp(promote)){
            message.setCode(0);
        }else {
            message.setCode(1);
            message.setMsg("更新失败");
        }
        return message;
    }
}
